/**
 * @param {string} s
 * @return {number}
 */
var longestSemiRepetitiveSubstring = function (s) {
  let left = 0, count = 1, max = 1, i = 1
  for (; i < s.length; i++) {
    if (s[i] == s[i - 1]) {
      if (count == 1) {
        count--
      }
      else {
        max = Math.max(max, i - left)
        left = i - 1
        i--
        count = 1
      }
    }

  }
  max = Math.max(max, i - left)
  return max
};

longestSemiRepetitiveSubstring('5459')